#ifndef __SPI_FLASH_H
#define __SPI_FLASH_H

	#ifdef cplusplus
 extern "C" {
#endif
#include "gd32f30x.h"
#include <stdio.h>




 void BufferWriteI2c(u16 address, u8 * record_buffer, u16 length);
 void BufferReadI2c(u16 address, u8 * buffer_read, u16 length);

 unsigned long ReadUlong(unsigned int address);
 void SaveUlong(unsigned long total_number,unsigned int address);
 unsigned char ReadUchar(unsigned int address);
 void SaveUchar(unsigned char save_data,unsigned int address);
 unsigned int ReadUint(unsigned int address);
 void SaveUint(unsigned int save_data,unsigned int address);

void SaveRecord(u16 address ,u8 * record_buffer);
unsigned int GetCustomerRecord(char * customer_name, u8 * return_record);

void SPI_FLASH_Init(void);
void SPI_FLASH_SectorErase(u32 SectorAddr);
void SPI_FLASH_BulkErase(void);
void SPI_FLASH_PageWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
void SPI_FLASH_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
void SPI_FLASH_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead);
u32 SPI_FLASH_ReadID(void);
u32 SPI_FLASH_ReadDeviceID(void);
void SPI_FLASH_StartReadSequence(u32 ReadAddr);
void SPI_Flash_PowerDown(void);
void SPI_Flash_WAKEUP(void);


u8 SPI_FLASH_ReadByte(void);
u8 SPI_FLASH_SendByte(u8 byte);
u16 SPI_FLASH_SendHalfWord(u16 HalfWord);
void SPI_FLASH_WriteEnable(void);
void SPI_FLASH_WaitForWriteEnd(void);


#endif /* __SPI_FLASH_H */
